#include "lb_deletbook.h"
#include "ui_lb_deletbook.h"


#include <QString>
#include <QMessageBox>
#include <QFile>
#include <QTextStream>
#include <QIODevice>
#include <QDebug>
#include <QPalette>


//pass
LB_deletbook::LB_deletbook(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LB_deletbook)
{
    ui->setupUi(this);

    //QPixmap pixmap = QPixmap("D://Qt//workspace//bookManager//pictures//xiyang.jpg").scaled(this->size());
    QPixmap pixmap = QPixmap("D://CsSoftware//Qt//__MyFiles//workspace//bookManager//pictures//dog.jpg").scaled(this->size());
    QPalette palette(this->palette());
    palette.setBrush(QPalette::Background,pixmap);
    this->setPalette(palette);

}
//pass
LB_deletbook::~LB_deletbook()
{
    delete ui;
}
//pass
void LB_deletbook::on_pushButton_clicked()
{
    QString del_isbn = this->ui->le_delete->text();
    int i = 0;
    int check = 0;
    for(i = 0;i < 100;i++){
        if(del_isbn == dataArray[i].isbn){
            QString content = "ISBN:" + dataArray[i].isbn + '\n' + "书名：" + dataArray[i].bookTitle + '\n' + "作者：" + dataArray[i].author + '\n' + "出版社：" + dataArray[i].publisher
                    + '\n' + "进书日期：" + dataArray[i].dataAdded + '\n' + "库存量：" + dataArray[i].qtyOnHand + '\n' + "批发价：" + dataArray[i].wholesale + '\n' + "零售价" + dataArray[i].retail;
            int ans = QMessageBox::question(this,"请确要删除该书吗？？",content,"Yes","No");
            if(ans == 0){
                dataArray[i].removeBook(i);//如果要删除一本书,将它的existOrNot置为false，置为false的数组元素将不能将自己的信息储存到文件中
                qDebug()<<"删除"<<dataArray[i].isbn;
            }
            check = 1;
            break;
        }
    }
    if(check == 0) QMessageBox::critical(this,"错误","找不到该书！！","确定");
}

void LB_deletbook::on_pushButton_2_clicked()
{
    this->close();
}
